require(['config'], function () {
    require(['jquery'], function () {
        require(['jquery-cookie'], function () {
            // 登录元素
            this.$logout = $('#logout');
            this.$loginname = $('#loginname');
            this.$register = $('#register');
            this.$login = $('#login');
            let _this=this;
            //自动登录
            this.autologin = function () {
                let logindata = $.cookie('loginname');
                if (logindata) {
                    // console.log(logindata);
                    this.$logout.show();
                    this.$loginname.children('a').html(logindata);
                    this.$loginname.show();
                    this.$login.hide();
                    this.$register.hide();
                } else {
                    this.$logout.hide();
                    this.$loginname.hide();
                    this.$login.show();
                    this.$register.show();   
                }
            }
            this.$logout.on('click', function () {
                $.cookie('loginname', null, { expires: -1 });
                window.location.reload()
            });
            this.autologin();
        });
    });
});
